package com.motu.monstercity.server.game.logic;

import com.motu.monstercity.server.game.commondata.partner.PartnerMain;
import com.motu.monstercity.server.game.userdata.*;
import com.motu.vertx.module.utility.model.EntityManager;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonArray;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.jar.JarEntry;

public class PartnerUserData extends PartnerBaseData {
    public static UserPartner getUserPartner(long userId, int partnerId) {
        return (UserPartner) EntityManager.getEntity(UserPartner.class, userId, partnerId);
    }

    // 获取UserPartner列表
    public static List<UserPartner> getUserPartnerList(long userId) {
        List<UserPartner> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(UserPartner.class, userId)) {
            UserPartner entity = (UserPartner) model;
            PartnerMain partnerMain = PartnerManager.getPartnerMain(entity.getPartnerId());
            if (partnerMain == null) {
                entity.delete();
            } else {
                list.add(entity);
            }
        }
        return list;
    }

    // 根据干员id列表获取UserPartner列表
    public static List<UserPartner> getUserPartnerList(long userId, JsonArray jsonArray) {
        List<UserPartner> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(UserPartner.class, userId, jsonArray)) {
            UserPartner entity = (UserPartner) model;
            PartnerMain partnerMain = PartnerManager.getPartnerMain(entity.getPartnerId());
            if (partnerMain == null) {
                entity.delete();
            } else {
                list.add(entity);
            }
        }
        return list;
    }

    public static long getUserPartnerCount(long userId) {
        return EntityManager.getEntityCount(UserPartner.class, userId);
    }

    public static UserWeapon getUserWeapon(long userId, long dbid) {
        return (UserWeapon) EntityManager.getEntity(UserWeapon.class, userId, dbid);
    }

    public static List<UserWeapon> getUserWeaonList(long userId) {
        List<UserWeapon> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(UserWeapon.class, userId)) {
            UserWeapon entity = (UserWeapon) model;
            list.add(entity);
        }
        return list;
    }

    public static UserWeaponBook getUserWeaponBook(long userId, int weaponId) {
        return (UserWeaponBook) EntityManager.getEntity(UserWeaponBook.class, userId, weaponId);
    }

    public static long getUserWeaponCount(long userId) {
        return EntityManager.getEntityCount(UserWeapon.class, userId);
    }

    public static long getUserWeaponBookCount(long userId) {
        return EntityManager.getEntityCount(UserWeaponBook.class, userId);
    }

    // 获取UserWeaponBook列表
    public static List<UserWeaponBook> getUserWeaponBookList(long userId) {
        List<UserWeaponBook> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(UserWeaponBook.class, userId)) {
            UserWeaponBook entity = (UserWeaponBook) model;
            list.add(entity);
        }
        return list;
    }
}
